home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_util / bsrc_260.zip / SRC.ZIP / UPLOAD.C < prev    next >
C/C++ Source or Header  |  1996-02-20  |  6KB  |  177 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*          This module was originally written by Vince Perriello           */
  13. /*                                                                          */
  14. /*                BinkleyTerm Terminal/Script Upload Module                 */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #ifdef HAVE_HYDRA
  49. #include "hydra.h"
  50. #endif
  51.  
  52. /*
  53.  * Handle uploads from terminal mode.
  54.  * Note: filepath parameter below will be trashed if it's a wildcard!
  55.  */
  56.  
  57. int 
  58. Upload (char *filepath, int prot, char *extern_ptr)
  59. {
  60.     unsigned save1, save2, save3;
  61.     char *p;
  62.     struct FILEINFO fileinfo = {0};
  63.  
  64.     int err = 1;                /* Xmodem, Ymodem, Telink flag */
  65.  
  66.     if (dfind (&fileinfo, filepath, 0))
  67.         return (0);
  68.  
  69.     save1 = comm_bits;
  70.     save2 = parity;
  71.     save3 = stop_bits;
  72.     comm_bits = BITS_8;
  73.     parity = NO_PARITY;
  74.     stop_bits = STOP_1;
  75.     program_baud ();
  76.     XON_DISABLE ();
  77.  
  78.     /* If external protocol requested, call it */
  79.  
  80.     if (extern_ptr != NULL)
  81.         do_extern ("Send", prot, filepath);
  82.     else
  83.         switch (prot)
  84.         {
  85.         case 'X':
  86.         case 'Y':
  87.             err = Xmodem_Send_File (filepath, NULL);
  88.             break;
  89.  
  90.         default:
  91.  
  92.     /*
  93.      * Find the delimiter on the pathspec for use by the various
  94.      * batch protocols.
  95.      */
  96.  
  97.             p = strrchr (filepath, '\\');
  98.             if (p == NULL)
  99.                 p = strrchr (filepath, '/');
  100.             if (p == NULL)
  101.                 p = strchr (filepath, ':');
  102.             if (p == NULL)
  103.                 p = filepath;
  104.             else
  105.                 p++;
  106.  
  107. #ifdef HAVE_HYDRA
  108.             if (prot == 'H')
  109.                 hydra_init (hydra_options);
  110. #endif    /* HAVE_HYDRA */
  111.  
  112.     /*  At this point *p points to the location in the input
  113.      *  string where the prepended path information ends. All
  114.      *  we need to do, then, is to keep plugging in the stuff
  115.      *  we get from _dos_find(first|next) and transfer files.
  116.      *  We already have the first matching filename from the
  117.      *  _dos_findfirst we did above, so we use a "do" loop.
  118.      */
  119.  
  120.             do
  121.             {
  122.                 /* Append the current filename */
  123.                 (void) strcpy (p, fileinfo.name);
  124.  
  125.                 /* Send the file with the proper protocol */
  126.  
  127. #ifdef HAVE_HYDRA
  128.                 if (prot == 'H')
  129.                     err = (hydra (filepath, NULL) == XFER_ABORT) ? FALSE : TRUE;
  130.                 else
  131. #endif    /* HAVE_HYDRA */
  132.  
  133.                 if (prot == 'Z')
  134.                     err = Send_Zmodem (filepath, NULL, 0, 0);
  135.                 else
  136.                 {
  137.                     err = !Batch_Send (filepath);
  138.                 }
  139.             }
  140.             while ((err) && (!dfind (&fileinfo, NULL, 1)));
  141.  
  142.             /* Finish the proper protocol if need be */
  143.  
  144.             if (err)
  145.             {
  146.  
  147. #ifdef HAVE_HYDRA
  148.                 if (prot == 'H')
  149.                     (void) hydra (NULL, NULL);
  150.                 else
  151. #endif    /* HAVE_HYDRA */
  152.  
  153.                 if (prot == 'Z')
  154.                     (void) Send_Zmodem (NULL, NULL, END_BATCH, 0);
  155.                 else
  156.                     (void) Batch_Send (NULL);
  157.             }
  158.             break;
  159.         }
  160.  
  161. #ifdef HAVE_HYDRA
  162.     if (prot == 'H')
  163.         hydra_deinit();
  164. #endif
  165.  
  166.     (void) dfind (&fileinfo, NULL, 2);
  167.  
  168.     comm_bits = save1;
  169.     parity = save2;
  170.     stop_bits = save3;
  171.     program_baud ();
  172.     XON_ENABLE ();
  173.     gong ();
  174.  
  175.     return (err);
  176. }
  177.